<div class="admin_form">
  <% form_for(@blog_post, :url => polymorphic_path([:admin, @blog_post])) do |f| %>
    <div class="span-16 form">
      <div id="flash_message" class="error" style="display:<%= @blog_post.errors.blank? ? "none": "static" %>">
        <%= error_messages_for :blog_post %>
      </div>

      <div class="form_group span-16">   
        <div class="form_pair span-16">
          <%= f.label :title %>
          <%= f.text_field :title, :class => "span-16" %>
        </div>
      </div>

      <div class="form_group span-16">  
        <div class="form_pair">
          <label for="blog_post_body_markdown">Post <span class="quiet">(uses Markdown)</span></label>
          <%= f.text_area :body_markdown, :class => "span-16" %>
          <p><%= link_to_function "Preview", "", :id => "preview_trigger" %> | <%= link_to_function "Markdown Help", "", :id => "help_trigger" %> | <%= link_to "What the hell is Markdown?", "http://daringfireball.net/projects/markdown/syntax" %></p>
        </div>
      </div>

      <div class="markdown_help span-16">

        <div id="syntax" class="hidden">
          <p class="large" style="border-bottom:1px solid #ddd; margin-bottom:0px; padding-bottom:18px"><strong>Some Markdown Examples:</strong></p>
          <div class="span-8 markdown_examples">
            <dl>
              <dt><pre>### A Header</pre></dt>
              <dd><h3>A Header</h3></dd>

              <dt><pre>Now is the time for all good men</pre></dt>
              <dd><p>Now is the time for all good men</p></dd>

              <dt><pre>Some of these words *are italic*.</pre></dt>
              <dd><p>Some of these words <em>are italic</em>.</p></dd>
            </dl>
          </div>

          <div class="span-8 last markdown_examples">
            <dl>
              <dt><pre>Use two asterisks **for bold**.</pre></dt>
              <dd><p>Use two asterisks <strong>for bold</strong>.</p></dd>

              <dt><pre>Here's an [example link](http://example.com/)</pre></dt>
              <dd><p>Here's an <a href="http://example.com/">example link</a></p></dd>
            </dl>
          </div>
          <p><%= link_to "Complete Guide", "http://daringfireball.net/projects/markdown/syntax" %></p>
        </div>
        <div id="preview" class="hidden">

        </div>
      </div>
  
    </div>
    <div class="span-8 last tags">
      <% unless @tags.blank? %>
        <p><strong>Categories</strong></p>
        <% @tags.each do |t| %>
          <p><%= check_box_tag "blog_post[tag_ids][]", t.id, @blog_post.tags.include?(t) %>
          <%= t.name %></p>
        <% end %>
      <% end %>
    </div>

    <div class="buttons span-24">
      <%= f.hidden_field :author_id, :value => current_user.id %>
      
      <%= f.submit "Save Changes" %> 
      <% unless @blog_post.is_published %>
        <%= f.submit "Save &amp; Publish Changes" %>
      <% end %>
      or <%= link_to "cancel", :action => :index %>
    </div>
  <% end %>
</div>
<script type="text/javascript">
  var converter = new Showdown.converter();
  
  $j('#help_trigger').click(function() {
    $j('#syntax').slideToggle('fast', function() {
      $j('#syntax').toggleClass("hidden");
      if(!$j('#preview').hasClass("hidden")){
        $j('#preview').toggleClass("hidden");
        $j('#preview').slideToggle('fast');        
      }
    });
  });
  
  $j('#preview_trigger').click(function() {
    $j('#preview').slideToggle('fast', function() {
      $j('#preview').toggleClass("hidden");
      if(!$j('#syntax').hasClass("hidden")){
        $j('#syntax').toggleClass("hidden");
        $j('#syntax').slideToggle('fast');
      }      
      $j('#preview').html(converter.makeHtml($j("#blog_post_body_markdown").val()));
    });
  });
  
</script>

<style type="text/css" media="screen">
  
  .markdown_examples dl{}
  .markdown_examples dl dt{margin:0;}
  .markdown_examples dl dd{border-bottom:1px solid #ddd;}
  .hidden{display:none;}
</style>